﻿using GloboTicketAdmin.API.Models;
using GloboTicketAdmin.API.Models.Domain;
using GloboTicketAdmin.API.Repository;
using GloboTicketAdmin.API.Services.IService;
using SqlSugar;

namespace GloboTicketAdmin.API.Services
{
    public class EventService : BaseRepository<EventModel>, IEventService
    {
        private readonly ISqlSugarClient db;

        public EventService(ISqlSugarClient db) : base(db)
        {
            this.db = db;
        }
        public int AddEvent(List<EventModel> modelList)
        {
            return Insert(modelList);
        }

        public int DeleteEventById(Guid id)
        {
            return Delete(id);
        }

        public EventModel GetEventById(Guid id)
        {
            return db.Queryable<EventModel>().Includes(o => o.Category).Where(it => it.Id == id).First();
        }

        public int InsertEvent(EventModel model)
        {
            return Insert(model);
        }
        
        public int UpdateEventById(EventModel model, bool ignoreNullColumns = false)
        {
            return Update(model, ignoreNullColumns);
        }
        public int UpdateEventById(Guid guid, EventStatusModel model)
        {
            return db.Updateable<EventModel>()
                .SetColumns(it => it.EventStatus == model)
                .Where(it => it.Id == guid)
                .ExecuteCommand();
        }
        public List<EventModel> GetAllEvents()
        {
            var list = db.Queryable<EventModel>().Includes(o => o.Category).ToList();
            return list;
        }
    }
}
